package com.yugao.fintech.draper.admin.controller;

import com.yugao.fintech.draper.admin.service.LoginLogService;
import com.yugao.fintech.draper.auth.dto.LoginLogDTO;
import com.yugao.fintech.draper.core.model.ResultVO;
import com.yugao.fintech.draper.security.annotation.SecurityInner;
import com.yugao.fintech.draper.datasource.entity.PageResult;
import com.yugao.fintech.draper.admin.param.OperLogQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/operLog")
@RequiredArgsConstructor
@Tag(name = "操作日志管理")
public class LoginLogController {
	private final LoginLogService loginLogService;

	@Operation(summary = "查询操作日志列表分页")
	@GetMapping(value = "/pageQuery")
	public ResultVO<PageResult<LoginLogDTO>> pageQuery(@RequestBody OperLogQuery operLogQueryVo) {
		return ResultVO.success(PageResult.success(loginLogService.pageQuery(operLogQueryVo)));
	}

	@Operation(summary = "保存操作日志")
	@SecurityInner(inner = true)
	@PostMapping(value = "/add")
	public void add(@RequestBody LoginLogDTO loginLogDTO) {
		loginLogService.addOperLog(loginLogDTO);
	}

	@Operation(summary = "修改操作日志")
	@PostMapping(value = "/update")
	public ResultVO<Boolean> update(@RequestBody LoginLogDTO loginLogDTO) {
		return ResultVO.success(loginLogService.updateOperLog(loginLogDTO));
	}

	@Operation(summary = "删除操作日志")
	@DeleteMapping(value = "/delete")
	public ResultVO<Boolean> delete(Long id) {
		return ResultVO.success(loginLogService.deleteOperLog(id));
	}

	@Operation(summary = "获取操作日志信息")
	@GetMapping(value = "/findById")
	public ResultVO<LoginLogDTO> findById(Long id) {
		return ResultVO.success(loginLogService.findById(id));
	}

	@Operation(summary = "获取全部操作日志")
	@GetMapping(value = "/findAll")
	public ResultVO<List<LoginLogDTO>> findAll() {
		return ResultVO.success(loginLogService.findAll());
	}

}